﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769

namespace InTheHand.UI.ApplicationSettings
{
    internal sealed partial class AboutFlyout : SettingsFlyout
    {
        public AboutFlyout()
        {
            this.InitializeComponent();

            PublisherHyperlink.Content = "More from " + Windows.ApplicationModel.Package.Current.PublisherDisplayName;

            Color bgColor = InTheHand.ApplicationModel.Package.Current.BackgroundColor;
            if (bgColor != Colors.Transparent)
            {
                Color modColor = Color.FromArgb((byte)0xff, bgColor.R, bgColor.G, bgColor.B);
                this.HeaderBackground = new SolidColorBrush(modColor);
            }

            if(Windows.ApplicationModel.Package.Current.IsDevelopmentMode)
            {
                PublisherHyperlink.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            Windows.ApplicationModel.Store.LicenseInformation license = Windows.ApplicationModel.Store.CurrentApp.LicenseInformation;
            if (license.IsTrial && !Windows.ApplicationModel.Package.Current.IsDevelopmentMode)
            {
                PrimaryButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
                PrimaryButton.IsEnabled = true;
                PrimaryButton.Content = "buy";
            }

            this.DataContext = InTheHand.ApplicationModel.Package.Current;

            //Uri logoUri = new Uri("ms-appx:///" + Windows.ApplicationModel.Package.Current.Logo.LocalPath.Replace(Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "\\", "").Replace("\\", "/").Replace(".scale-100",""));
            //LogoImage.Source = new BitmapImage(logoUri) { CreateOptions = BitmapCreateOptions.None };
        }

        private async void PublisherButton_Click(object sender, RoutedEventArgs e)
        {
            await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:Publisher?name=" + Windows.ApplicationModel.Package.Current.PublisherDisplayName));
        }

        private async void PrimaryButton_Click(object sender, RoutedEventArgs e)
        {
            await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:PDP?PFN=" + Windows.ApplicationModel.Package.Current.Id.FamilyName));
        }
    }
}
